/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/5
 * Time: 13:45
 */
public class Solution {
    public String countAndSay(int n) {
        String ret = "1";
        if (n == 1) return ret;
        //解释n - 1次
        for (int i = 1; i < n; i++) {
            StringBuilder cur = new StringBuilder();
            int len = ret.length();
            for (int left = 0,right = 0;right < len;){
                while(right < len && ret.charAt(right) == ret.charAt(left)) right++;
                cur.append(right - left);
                cur.append(ret.charAt(left));
                left = right;
            }
            ret = cur.toString();
        }
        return ret;
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        String ret = solution.countAndSay(10);
        System.out.println(ret);
    }
}